package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.glide.GlideApp;

/**
 * Author: lkw
 * time:   2021/9/17 15:32
 * des:    选择上传图片的适配器
 */
public class AddPhotoAdapter extends AppAdapter<String> {

    public AddPhotoAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new HasViewHolder();
    }

    private final class HasViewHolder extends AppAdapter<?>.ViewHolder {

        private AppCompatImageView photo;

        private HasViewHolder() {
            super(R.layout.item_has_photo);
            photo = findViewById(R.id.iv_photo);
        }

        @Override
        public void onBindView(int position) {
            // 显示圆角的 ImageView
            GlideApp.with(getContext())
                    .load(getItem(position))
                    .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners((int) getResources().getDimension(R.dimen.dp_10))))
                    .into(photo);
        }
    }
}
